<?php

namespace App\Imports;

use App\Models\Service;
use App\Models\ServiceType;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

class ServiceImport implements ToCollection
{
    public function collection(Collection $rows)
    {

        $rows->shift();
        $rows->shift();
       
       
        foreach ($rows as $row) 
        {
            if(empty($row[0])||empty($row[1])) continue;
            $data['code'] = 'S'.date('YmdHis');
            $data['name'] = $row[0];
            $data['service_type_id'] = ServiceType::where(['name'=>$row[1]])->value('id');
            $data['price_type'] =  $row[4]=='工时定价'?2:1;
            $data['gongshi_fee'] = $row[5];
            $data['gongshi']     = $row[6];
            $data['price']       = $row[7];
            $data['base_price']  = $row[8];
            $data['remark']      = $row[9];
            Service::create($data);
        }


    }
}
